export default {
	data() {
		return {
			initial: {
				createdIsNeed: true,
				geturl: "",
				isPage: true,
				parm: {},
				page: 1,
				limit: 10,
				status: "loadmore",
				isPost: true,
				isflash:true,
				isReach:true
			},
		}
	},
	onShow(){
		this.initial.page = 1;
	},

	async onPullDownRefresh() {
		this.initial.page = 1;
		 await this.getGoods();
		setTimeout(function() {
			uni.stopPullDownRefresh()
		}, 1000)
	},
	onReachBottom() {
		if(!this.initial.isReach)return
		if (this.initial.status == 'nomore') {

		} else {
			this.getGoods()
		}
	},


	methods: {

		getGoods(callback) {
		  	 return new Promise((resolve, reject) => {
				 this.initial.status = 'loading';
				 let isPost=this.initial.isPost?'post':'get';
				this.$u[isPost](this.initial.geturl, {
				 	page: this.initial.isPage ? this.initial.page : '',
				 	limit: this.initial.isPage ? this.initial.limit : '',
				 	...this.initial.parm
				 },{
					"Content-Type": "application/json",
				}).then(res => {
					if(Array.isArray(res)){
						var resList = res;
					}else{
						var resList = res.data;
					}
				 	
				 	
				 	if (this.initial.page == 1) {
				 		this.list = []
				 	}
				 	if (resList.length > this.initial.limit-1) {
				 		this.initial.status = 'loadmore'
				 		this.initial.page++
				 	} else {
						
				 		this.initial.status = 'nomore'
				 	}
					
					
				 	this.list = [...this.list,...resList];
				 		
		
				 	if (callback) {
				 		this.$nextTick(() => {
				 			callback()
				 		})
				 	}
					resolve(res)
				 
				 });
			 })
			
		}
	}

}
